import { createStore } from 'vuex'
// import { ElMessage } from 'element-plus'
// import { getSess } from '@/api/user/auth'

export default createStore({
  state: {
    isUserLogined: false, // 用户是否登录
    user: null, // 存储用户数据
    isShowBreadcrumb: true, // 存储是否显示面包屑
  },
  getters: {
    getIsUserLogined: state => state.isUserLogined,
    getUser: state => state.user,
  },
  mutations: {
    setUserLogined(state, payload) {
      state.isUserLogined = payload;
    },
    setUser(state, user) {
      state.user = user;
    },
    setShowBreadcrumb(state, value) {
      state.isShowBreadcrumb = value;
    },
  },
  actions: {
    async getSessAction({ commit }, payload) {
      console.log(commit);
      console.log(payload);

      let rst_data = {}
      
      // 调用接口
      try {
        // const response = await getSess({});
        // const rst = response.data; // 设置获取到的数据
        // if (rst.errcode === 0) {
        //   console.log(rst.data)
        //   rst_data = rst.data
        //   commit('setUserLogined', rst.data.islogin);
        //   commit('setUser', rst.data.user);
        // } else {
        //   ElMessage.error(rst.msg)
        // }
      } catch (error) {
        console.error('Error fetching data:', error);
      }

      return rst_data;
    },
  },
  modules: {
  }
})
